#include "../../lvgl/lvgl.h"
#include "ui.h"

lv_obj_t * ui_page4 = NULL;

lv_obj_t * kongtiao_modify = NULL;
lv_obj_t * led_modify = NULL;
lv_obj_t * chuanglian_modify = NULL;

lv_obj_t * kb = NULL;
lv_obj_t * modify_value = NULL;

static void event_Demo(lv_event_t *e)
{
    kongtiao_modify_flag = 0;
    led_modify_flag = 0;
    chuanglian_modify_flag = 0;
    lv_textarea_set_text(modify_value, "");
    lv_textarea_set_placeholder_text(modify_value, "");
    lv_scr_load(ui_page3);
}

void Page_4()
{
    ui_page4 = lv_obj_create(NULL);
    lv_obj_set_style_text_font(ui_page4 , &lv_font_montserrat_28 , 0 );

    //创建退出修改初值的按钮，设定好标签文本以及回调函数
    lv_obj_t * Demo = lv_btn_create(ui_page4);
    lv_obj_set_width(Demo, lv_pct(15));
    lv_obj_set_height(Demo, lv_pct(10));
    lv_obj_set_x(Demo, lv_pct(5));
    lv_obj_set_y(Demo, lv_pct(5));
    lv_obj_set_align(Demo, LV_ALIGN_TOP_LEFT);
    lv_obj_t * Demo_label = lv_label_create(Demo);
    lv_obj_set_width(Demo_label, lv_pct(100));
    lv_obj_set_height(Demo_label, lv_pct(100));
    lv_obj_set_align(Demo_label , LV_ALIGN_CENTER);
    lv_obj_add_style(Demo_label, &style_32, 0); //给标签添加字体风格
    lv_label_set_text(Demo_label, "退出");
    lv_obj_add_event_cb(Demo, event_Demo, LV_EVENT_CLICKED, NULL);

    lv_obj_t * title = lv_label_create(ui_page4);
    lv_obj_set_width(title, lv_pct(60));
    lv_obj_set_height(title, lv_pct(15));
    lv_obj_set_x(title, lv_pct(3));
    lv_obj_set_y(title, lv_pct(5));
    lv_obj_set_align(title, LV_ALIGN_TOP_MID);
    lv_obj_add_style(title, &style_50, 0);
    lv_label_set_text(title , "选择要修改初值的电器");


    //创建修改空调初值的按钮，设定好标签文本以及回调函数
    kongtiao_modify = lv_btn_create(ui_page4);
    lv_obj_set_width(kongtiao_modify, lv_pct(15));
    lv_obj_set_height(kongtiao_modify, lv_pct(10));
    lv_obj_set_x(kongtiao_modify, lv_pct(25));
    lv_obj_set_y(kongtiao_modify, lv_pct(20));
    lv_obj_set_align(kongtiao_modify, LV_ALIGN_TOP_LEFT);
    lv_obj_t * kongtiao_modify_label = lv_label_create(kongtiao_modify);
    lv_obj_set_width(kongtiao_modify_label, lv_pct(100));
    lv_obj_set_height(kongtiao_modify_label, lv_pct(100));
    lv_obj_set_align(kongtiao_modify_label , LV_ALIGN_CENTER);
    lv_obj_add_style(kongtiao_modify_label, &style_32, 0); //给标签添加字体风格
    lv_label_set_text(kongtiao_modify_label, "空调");
    lv_obj_add_event_cb(kongtiao_modify, event_value_modify, LV_EVENT_CLICKED, NULL);

    //创建修改空调初值的按钮，设定好标签文本以及回调函数
    led_modify = lv_btn_create(ui_page4);
    lv_obj_set_width(led_modify, lv_pct(15));
    lv_obj_set_height(led_modify, lv_pct(10));
    lv_obj_set_x(led_modify, lv_pct(45));
    lv_obj_set_y(led_modify, lv_pct(20));
    lv_obj_set_align(led_modify, LV_ALIGN_TOP_LEFT);
    lv_obj_t * led_modify_label = lv_label_create(led_modify);
    lv_obj_set_width(led_modify_label, lv_pct(100));
    lv_obj_set_height(led_modify_label, lv_pct(100));
    lv_obj_set_align(led_modify_label , LV_ALIGN_CENTER);
    lv_obj_add_style(led_modify_label, &style_32, 0); //给标签添加字体风格
    lv_label_set_text(led_modify_label, "灯光");
    lv_obj_add_event_cb(led_modify, event_value_modify, LV_EVENT_CLICKED, NULL);

    //创建修改空调初值的按钮，设定好标签文本以及回调函数
    chuanglian_modify = lv_btn_create(ui_page4);
    lv_obj_set_width(chuanglian_modify, lv_pct(15));
    lv_obj_set_height(chuanglian_modify, lv_pct(10));
    lv_obj_set_x(chuanglian_modify, lv_pct(65));
    lv_obj_set_y(chuanglian_modify, lv_pct(20));
    lv_obj_set_align(chuanglian_modify, LV_ALIGN_TOP_LEFT);
    lv_obj_t * chuanglian_modify_label = lv_label_create(chuanglian_modify);
    lv_obj_set_width(chuanglian_modify_label, lv_pct(100));
    lv_obj_set_height(chuanglian_modify_label, lv_pct(100));
    lv_obj_set_align(chuanglian_modify_label , LV_ALIGN_CENTER);
    lv_obj_add_style(chuanglian_modify_label, &style_32, 0); //给标签添加字体风格
    lv_label_set_text(chuanglian_modify_label, "窗帘");
    lv_obj_add_event_cb(chuanglian_modify, event_value_modify, LV_EVENT_CLICKED, NULL);

    modify_value = lv_textarea_create(ui_page4);
    lv_obj_align(modify_value, LV_ALIGN_CENTER , 0, -50);
    lv_textarea_set_one_line(modify_value , true );
    lv_obj_set_size(modify_value, 400, 60);
    lv_textarea_set_placeholder_text(modify_value, "");
    lv_obj_add_event_cb(modify_value, ta_event_cb, LV_EVENT_ALL, kb);
    
    lv_obj_t * finish = lv_btn_create(ui_page4);
    lv_obj_align(finish, LV_ALIGN_CENTER , 0, 50);
    lv_obj_set_size(finish, lv_pct(20), lv_pct(10));
    lv_obj_t * label = lv_label_create ( finish );
    lv_obj_center( label );
    lv_obj_add_style(label , &style_32 , 0);
    lv_label_set_text(  label , "确定" );
    lv_obj_add_event_cb( finish ,  finishFun ,  LV_EVENT_CLICKED , NULL );
    
    kb = lv_keyboard_create(ui_page4);
    lv_obj_add_flag(kb, LV_OBJ_FLAG_HIDDEN);
}